//
//  ZtEidtBar.m
//  CarTown
//
//  Created by xionghao on 15/8/28.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "ZtEidtBar.h"

@implementation ZtEidtBar
-(instancetype)initWithBtnTitleArray:(NSArray *)titles WithDelegate:(id<EidtBarDelegate>)delegate{
    if (self=[super init]) {
        self.frame= CGRectMake(0, XHScreenheight-54, XHScreenwidth, 54);
        self.backgroundColor=RGBACOLOR(249, 249, 249, 0.95);
        self.layer.borderWidth=0.5;
        self.layer.borderColor=[UIColorWithRGB(202, 208, 207) CGColor];
        CGFloat x;
        CGFloat y=8;
        CGFloat height=36;
        int count=titles.count;
        if (count==0) {
            count=2;
            titles=@[@"删除",@"修改"];
        }
        self.delegate=delegate;
      CGFloat width=(XHScreenwidth-32-8*(count-1))/count;
        for (int i=0; i<count; i++) {
            UIButton *btn=[[UIButton alloc]init];
            x=16+(width+8)*i;
            btn.frame=CGRectMake(x, y, width, height);
            if (i!=count-1) {
                [btn setBackgroundImage:[UIImage imageWithStretchableName:@"bo_hbian"] forState:UIControlStateNormal];
                [btn setTitleColor:tintblue forState:UIControlStateNormal];
            }else{
            
            [btn setBackgroundImage:[UIImage imageWithStretchableName:@"bo_lbian"] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            }
            [btn setTitle:titles[i] forState:UIControlStateNormal];
            btn.tag=i;
           
            [btn addTarget:self action:@selector(toolbarmenuclick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
        }

    }
    return self;
}

-(void)updatetitle:(NSArray *)titles{
    for (int i=0; i<self.subviews.count; i++) {
        UIButton *btn=self.subviews[i];
        [btn setTitle:titles[i] forState:UIControlStateNormal];
    }
    
}

-(void)toolbarmenuclick:(UIButton *)btn{
    if ([_delegate respondsToSelector:@selector(EidtClickWithIndex:)]) {
        [_delegate EidtClickWithIndex:btn.tag];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
